home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / pascal / xlibpas2.zip / XLIB2.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1994-06-12  |  16.8 KB  |  459 lines

  1. {╔══════════════════════════════════════════════════════════════════════════╗
  2.  ║                                                                          ║
  3.  ║                   XLIB v2.0 for BORLAND/TURBO PASCAL 7.0                 ║
  4.  ║                Tristan Tarrant ( tristant@cogs.susx.ac.uk )              ║
  5.  ║                                                                          ║
  6.  ╠══════════════════════════════════════════════════════════════════════════╣
  7.  ║ Credits :                                                                ║
  8.  ║   Michael Abrash - Concept and Algorithms                                ║
  9.  ║   Themie Gouthas - Original code                                         ║
  10.  ║   Michael McKenzie - Lots of code                                        ║
  11.  ║   Tore Bastiansen - Virtual VSync code                                   ║
  12.  ╚══════════════════════════════════════════════════════════════════════════╝}
  13.  
  14. {$A+,B-,E-,G+,N-,O-,P-,Q-,S-,T-,X+}
  15.  
  16. {$IFDEF DPMI}
  17. {$C FIXED PRELOAD PERMANENT}
  18. {$ENDIF}
  19.  
  20. Unit XLib2;
  21.  
  22. Interface
  23.  
  24. Type
  25.     Vertex = record
  26.         x, y : word;
  27.     end;
  28.     VBMInfoStruc = record
  29.         Size, ImageWidth, ImageHeight : word;
  30.     end;
  31.     VBMAlignmentStruc = record
  32.         ImagePtr, MaskPtr : word;
  33.     end;
  34.     AlignmentHeader = record
  35.         size, ImageWidth, ImageHeight : word;
  36.         alignments : array[0..3] of
  37.         record
  38.              ImagePtr, MaskPtr : word;
  39.         end;
  40.     end;
  41.     LBMHeader = record
  42.         width, height : byte;
  43.     end;
  44.     PAlignmentHeader = ^AlignmentHeader;
  45.  
  46. Const
  47.     XMode320x200  = 0;
  48.     XMode320x240  = 1;
  49.     XMode360x200  = 2;
  50.     XMode360x240  = 3;
  51.     XMode376x282  = 4;
  52.     XMode320x400  = 5;
  53.     XMode320x480  = 6;
  54.     XMode360x400  = 7;
  55.     XMode360x480  = 8;
  56.     XMode360x360  = 9;
  57.     XMode376x308  = 10;
  58.     XMode376x564  = 11;
  59.     XMode256x200  = 12;
  60.     XMode256x240  = 13;
  61.     XMode256x224  = 14;
  62.     XMode256x256  = 15;
  63.     XMode360x270  = 16;
  64.     XMode400x300  = 17;
  65.  
  66.     LastMode      = 17;
  67.  
  68.     RBackward     = 0;
  69.     RForward      = 1;
  70.     InvalidXMode  = -1;
  71.     Error         = 1;
  72.     AlignData     = 6;
  73.     LeftPressed   = 1;
  74.     RightPressed  = 2;
  75.  
  76.     X320Y200 : array[0..4] of word =
  77.         ( $0200, $0014, $E317, 320, 200 );
  78.     X320Y240 : array[0..12] of word =
  79.         ( $0AE3, $0D06, $3E07, $4109, $EA10, $AC11, $DF12, $0014, $E715, $0616,
  80.                 $E317, 320, 240 );
  81.     X360Y200 : array[0..10] of word =
  82.         ( $08E7, $6B00, $5901, $5A02, $8E03, $5E04, $8A05, $0014, $E317, 360,
  83.                 200 );
  84.     X360Y240 : array[0..19] of word =
  85.         ( $11E7, $6b00, $5901, $5A02, $8E03, $5E04, $8A05, $0D06, $3E07, $4109,
  86.                 $EA10, $AC11, $DF12, $2D13, $0014, $E715, $0616, $E317, 360, 240 );
  87.     X376Y282 : array[0..20] of word =
  88.         ( $12E7, $6e00, $5d01, $5e02, $9103, $6204, $8f05, $6206, $f007, $6109,
  89.                 $310f, $3710, $8911, $3312, $2f13, $0014, $3C15, $5C16, $e317, 376,
  90.                 282 );
  91.     X256Y400 : array[0..11] of word  =
  92.         ( $08E3, $5f00, $3f01, $4202, $9f03, $4c04, $0005, $4009, $0014, $E317,
  93.                 256, 400 );
  94.     X256Y480 : array[0..18] of word =
  95.         ( $10e3, $5f00, $3f01, $4202, $9f03, $4c04, $0005, $0d06, $3e07, $4009,
  96.                 $ea10, $ac11, $df12, $0014, $e715, $0616, $e317, 256, 480 );
  97.     X320Y400 : array[0..5] of word =
  98.         ( $03e3, $4009, $0014, $e317, 320, 400 );
  99.     X320Y480 : array[0..12] of word =
  100.         ( $0AE3, $0D06, $3E07, $4009, $EA10, $AC11, $DF12, $0014, $E715, $0616,
  101.                 $E317, 320, 480 );
  102.     X360Y400 : array[0..11] of word =
  103.         ( $09E7, $6B00, $5901, $5A02, $8E03, $5E04, $8A05, $4009, $0014, $E317,
  104.                 360, 400 );
  105.     X360Y480 : array[0..19] of word =
  106.         ( $11E7, $6B00, $5901, $5A02, $8E03, $5E04, $8A05, $0D06, $3E07, $4009,
  107.                 $EA10, $AC11, $DF12, $2D13, $0014, $E715, $0616, $E317, 360, 480 );
  108.     X360Y360 : array[0..17] of word =
  109.         ( $0FE7, $6b00, $5901, $5A02, $8E03, $5E04, $8A05, $4009, $8810, $8511,
  110.                 $6712, $2D13, $0014, $6D15, $BA16, $E317, 360, 360 );
  111.     X376Y308 : array[0..20] of word =
  112.         ( $12E7, $6E00, $5D01, $5E02, $9103, $6204, $8F05, $6206, $0F07, $4009,
  113.                 $310F, $3710, $8911, $3312, $2F13, $0014, $3C15, $5C16, $E317, 376,
  114.                 308 );
  115.     X376Y564 : array[0..20] of word =
  116.         ( $12E7, $6E00, $5D01, $5E02, $9103, $06204, $8F05, $6206, $F007, $6109,
  117.                 $310F, $3710, $8911, $3312, $2F13, $0014, $3C15, $5C16, $E317, 376,
  118.                 564 );
  119.     X256Y200 : array[0..10] of word =
  120.         ( $08e3, $5f00, $3f01, $4202, $9f03, $4c04, $0005, $0014, $e317, 256,
  121.                 200 );
  122.     X256Y240 : array[0..18] of word =
  123.         ( $10e3, $5f00, $3f01, $4202, $9f03, $4c04, $0005, $0d06, $3e07, $4109,
  124.                 $ea10, $ac11, $df12, $0014, $e715, $0616, $e317, 256, 240 );
  125.     X256Y224 : array[0..20] of word =
  126.         ( $12e3, $5f00, $3f01, $4202, $8203, $4a04, $9a05, $0b06, $3e07, $0008,
  127.                 $4109, $da10, $9c11, $bf12, $2013, $0014, $c715, $0416, $e317, 256,
  128.                 224 );
  129.     X256Y256 : array[0..20] of word =
  130.         ( $12e3, $5f00, $3f01, $4002, $8203, $4a04, $9a05, $2306, $b207, $0008,
  131.             $6109, $0a10, $ac11, $ff12, $2013, $0014, $0715, $1a16, $e317, 256,
  132.             256 );
  133.     X360Y270 : array[0..20] of word =
  134.         ( $12e7, $6b00, $5901, $5a02, $8e03, $5e04, $8a05, $3006, $f007, $0008,
  135.             $6109, $2010, $a911, $1b12, $2d13, $0014, $1f15, $2f16, $e317, 360,
  136.             270 );
  137.     X400Y300 : array[0..20] of word =
  138.         ( $12a7, $7100, $6301, $6402, $9203, $6504, $8205, $4606, $1f07, $0008,
  139.             $4009, $3110, $8011, $2b12, $3213, $0014, $2f15, $4416, $e317, 400,
  140.             300 );
  141.  
  142.     ModeTable : array[0..17] of word =
  143.         ( Ofs(X320Y200[0]), Ofs(X320Y240[0]), Ofs(X360Y200[0]), Ofs(X360Y240[0]),
  144.             Ofs(X376Y282[0]), Ofs(X320Y400[0]), Ofs(X320Y480[0]), Ofs(X360Y400[0]),
  145.             Ofs(X360Y480[0]), Ofs(X360Y360[0]), Ofs(X376Y308[0]), Ofs(X376Y564[0]),
  146.             Ofs(X256Y200[0]), Ofs(X256Y240[0]), Ofs(X256Y224[0]), Ofs(X256Y256[0]),
  147.             Ofs(X360Y270[0]), Ofs(X400Y300[0]) );
  148.  
  149.     MirrorTable : array[0..255] of byte =
  150.         ( 0,128, 64,192, 32,160, 96,224, 16,144, 80,208, 48,176,112,240,
  151.             8,136, 72,200, 40,168,104,232, 24,152, 88,216, 56,184,120,248,
  152.             4,132, 68,196, 36,164,100,228, 20,148, 84,212, 52,180,116,244,
  153.          12,140, 76,204, 44,172,108,236, 28,156, 92,220, 60,188,124,252,
  154.             2,130, 66,194, 34,162, 98,226, 18,146, 82,210, 50,178,114,242,
  155.          10,138, 74,202, 42,170,106,234, 26,154, 90,218, 58,186,122,250,
  156.             6,134, 70,198, 38,166,102,230, 22,150, 86,214, 54,182,118,246,
  157.          14,142, 78,206, 46,174,110,238, 30,158, 94,222, 62,190,126,254,
  158.             1,129, 65,193, 33,161, 97,225, 17,145, 81,209, 49,177,113,241,
  159.             9,137, 73,201, 41,169,105,233, 25,153, 89,217, 57,185,121,249,
  160.             5,133, 69,197, 37,165,101,229, 21,149, 85,213, 53,181,117,245,
  161.          13,141, 77,205, 45,173,109,237, 29,157, 93,221, 61,189,125,253,
  162.             3,131, 67,195, 35,163, 99,227, 19,147, 83,211, 51,179,115,243,
  163.          11,139, 75,203, 43,171,107,235, 27,155, 91,219, 59,187,123,251,
  164.             7,135, 71,199, 39,167,103,231, 23,151, 87,215, 55,183,119,247,
  165.          15,143, 79,207, 47,175,111,239, 31,159, 95,223, 63,191,127,255 );
  166.  
  167.     PelPanMask : array[0..3] of byte =
  168.         ( 0, 2, 4, 6 );
  169.     LeftClipPlaneMask  : array[0..3] of byte =
  170.         ( $0F, $0E, $0C, $08 );
  171.     RightClipPlaneMask : array[0..3] of byte =
  172.         ( $0F, $01, $03, $07 );
  173.     ColumnMask : array[0..3] of byte =
  174.         ( $11, $22, $44, $88 );
  175.     LeftMaskTable : array[0..8] of byte =
  176.         ( 0, $ff, $ee, 0, $cc, 0, 0, 0, $88 );
  177.     RightMaskTable: array[0..8] of byte =
  178.         ( 0, $11, $33, 0, $77, 0, 0, 0, $ff );
  179.     InitMouseDef : array[0..13] of byte =
  180.         (1,3,7,15,31,63,127,255,31,27,48,48,96,96);
  181.     LeftDelay : array[0..3] of byte =
  182.         ( 0, 1, 2, 4 );
  183.     RightDelay : array[0..3] of byte =
  184.         ( 0, 4, 2, 1 );
  185.     PS2Cards : array[0..12] of byte = ( 0,1,2,2,4,3,2,5,6,2,8,7,8 );
  186.  
  187.     WhenToDraw : array[0..31] of byte = ( 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3,
  188.             2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5 );
  189.  
  190. Var
  191.     InGraphics,
  192.     ErrorValue,
  193.     FontDriverActive,
  194.     CharHeight,
  195.     CharWidth,
  196.     FirstChar,
  197.     UserChHeight,
  198.     UserChWidth,
  199.     UserFirstCh,
  200.     DoubleScanFlag : Byte;
  201.     CurrXMode,
  202.     ScrnPhysicalByteWidth,
  203.     ScrnPhysicalPixelWidth,
  204.     ScrnPhysicalHeight,
  205.     SplitScrnOffs,
  206.     SplitScrnScanLine,
  207.     SplitScrnVisibleHeight,
  208.     SplitScrnActive,
  209.     Page0Offs,
  210.     Page1Offs,
  211.     Page2Offs,
  212.     ScrnLogicalByteWidth,
  213.     ScrnLogicalPixelWidth,
  214.     ScrnLogicalHeight,
  215.     MaxScrollX,
  216.     MaxScrollY,
  217.     DoubleBufferActive,
  218.     TripleBufferActive,
  219.     VisiblePageIdx,
  220.     HiddenPageOffs,
  221.     VisiblePageOffs,
  222.     WaitingPageOffs,
  223.     NonVisualOffs,
  224.     TopClip,
  225.     BottomClip,
  226.     LeftClip,
  227.     RightClip,
  228.     PhysicalStartPixelX,
  229.     PhysicalStartByteX,
  230.     PhysicalStartY,
  231.     VsyncHandlerActive,
  232.     MouseRefreshFlag,
  233.     StartAddressFlag,
  234.     WaitingStartLow,
  235.     WaitingStartHigh,
  236.     WaitingPelPan,
  237.     VsyncPaletteStart,
  238.     VsyncPaletteCount,
  239.     MirrorTableOffs,
  240.     MouseInstalled,
  241.     MouseHidden,
  242.     MouseButtonStatus,
  243.     MouseButtonCount,
  244.     MouseX,
  245.     MouseY,
  246.     BGSaveOffs,
  247.     TopBound,
  248.     BottomBound,
  249.     LeftBound,
  250.     RightBound,
  251.     MouseVersion,
  252.     ScreenSeg, 
  253.     Seg0000,
  254.     SelectorInc: word;
  255.     MouseFrozen,
  256.     MouseColor,
  257.     MouseType,
  258.     MouseIRQ,
  259.     inhandler : byte;
  260.     FontPtr,
  261.     UserFontPtr,
  262.     F8x8Ptr,
  263.     F8x14Ptr, 
  264.     OldTimerIntVar : pointer;
  265.     MouseMask : array[0..167] of byte;
  266.     VSyncPaletteBuffer : array[0..767] of byte;
  267.  
  268. Function  XSetMode( Mode, WidthInPixels : Word ) : Word;
  269. Procedure XSelectDefaultPlane( Plane : Byte );
  270. Procedure XSetSplitscreen( Line : Word );
  271. Procedure XSetStartAddr( X, Y : Word );
  272. Procedure XHideSplitscreen;
  273. Procedure XShowSplitscreen;
  274. Procedure XAdjustSplitscreen( Line : Word );
  275. Procedure XSetDoubleBuffer( PageHeight : Word );
  276. Procedure XSetTripleBuffer( PageHeight : word );
  277. Procedure XPageFlip( X, Y : Word );
  278. Procedure XSetClipRect( Left, Top, Right, Bottom : Word );
  279. Procedure XTextMode;
  280. Procedure XWaitVsync;
  281. Procedure XLine( x1, y1, x2, y2, Color, PgOffs : word );
  282. Procedure XPutPix( X,Y,PgOfs,Color:word );
  283. Function  XGetPix( x,y,PageBase:word ) : word;
  284. Procedure XRectFill( StartX,StartY,EndX,EndY,PageBase,Color:word );
  285. Procedure XRectPattern( StartX,StartY,EndX,EndY,PageBase:word; var Pattern);
  286. Procedure XCpVidPage( SourceOffs, DestOffs : word );
  287. Procedure XCpVidRect( SrcStartX,SrcStartY,SrcEndX,SrcEndY,DestStartX,
  288.                                             DestStartY,SrcPageBase,DestPageBase,SrcBitmapW,
  289.                                             DestBitmapW:word );
  290. Procedure XShiftRect( SrcLeft,SrcTop,SrcRight,SrcBottom,DestLeft,DestTop,
  291.                                             ScreenOffs:word );
  292. Procedure XCircle( Left, Top, Diameter, Color, ScreenOffs:word );
  293. Procedure XFilledCircle( Left, Top, Diameter, Color, ScreenOffs:word );
  294. Procedure XGetPalStruc( var PalBuff; NumColors,StartColor:word );
  295. Procedure XGetPalRaw( Var PalBuff; NumColors,StartColor:word );
  296. Procedure XPutPalStruc( Var CompPalBuff );
  297. Procedure XTransposePalStruc( Var CompPalBuff; StartColor:word );
  298. Procedure XPutPalRaw( Var PalBuff; NumColors,StartColor:word );
  299. Procedure XSetRGB( ColorIndex,R,G,B:byte );
  300. Procedure XRotPalStruc( Var PalBuff; Direction:word );
  301. Procedure XRotPalRaw( Var PalBuff; Direction, NumColors:word );
  302. Function  XCpContrastPalStruc( Var PalSrcBuff,PalDestBuff; Intensity:byte ) : word;
  303. Procedure XPutContrastPalStruc( Var CompPalBuff; Intensity:byte );
  304. Function  XCharPut( Chr:char; X, Y, ScrnOffs, Color:word ) : byte;
  305. Procedure XSetFont( FontID : word );
  306. Procedure XTextInit;
  307. Procedure XRegisterUserFont( var FontToRegister );
  308. Function  XGetCharWidth( ch : char ) : byte;
  309. Function  XPrintf( x, y, ScrnOffs, Color : word; s : string ) : integer;
  310. Function  XBgPrintf( x, y, ScrnOffs, fgcolor, bgcolor : word; s : string ) : integer;
  311. Function  XCentre( x, y, ScrnOffs, color : word; s : string ) : integer;
  312. Function  XBgCentre( x, y, ScrnOffs, fgcolor, bgcolor : word; s : string ) : integer;
  313. function  XStrWidth( s : string ) : integer;
  314. Procedure XTriangle( X0, Y0, X1, Y1, X2, Y2, Color, PageOffset:word );
  315. Procedure XPolygon( var vertices; numvertices, Color, PageOffset:word );
  316. Procedure XPutCursor( X, Y, TopClip, BottomClip, ScrnOffs : word );
  317. Procedure XDefineMouseCursor( var MouseDef; MouseColor:byte );
  318. procedure XMouseInit;
  319. Procedure XMouseWindow( x0, y0, x1, y1:word );
  320. procedure XShowMouse;
  321. Procedure XHideMouse;
  322. Procedure XMouseRemove;
  323. Procedure XPositionMouse( X, Y : word );
  324. Procedure XUpdateMouse;
  325. Function  XFloodFill( X, Y, PgOfs, Color:word ) : word;
  326. Function  XBoundaryFill( X, Y, PgOfs, BoundaryColor, Color : word ) : word;
  327. Procedure XInstallVSyncHandler( VrtsToSkip : word );
  328. Procedure XRemoveVSyncHandler;
  329. Procedure XSetUserVSyncHandler;
  330.  
  331. Implementation
  332.  
  333. {$IFDEF DPMI}
  334. {$L XLIB2.OBP}
  335. procedure __a000h; far; external 'KERNEL' index $00AE;
  336. procedure __c000h; far; external 'KERNEL' index $00C3;
  337. procedure __AHIncr; far;        external 'KERNEL' index $0072;
  338. procedure __0000h; far; external 'KERNEL' index $00B7;
  339. {$ELSE}
  340. {$L XLIB2.OBJ}
  341. {$ENDIF}
  342.  
  343. Function  XSetMode( Mode, WidthInPixels : Word ) : Word; external;
  344. Procedure XSelectDefaultPlane( Plane : Byte ); external;
  345. Procedure XSetSplitscreen( Line : Word ); external;
  346. Procedure XSetStartAddr( X, Y : Word ); external;
  347. Procedure XHideSplitscreen; external;
  348. Procedure XShowSplitscreen; external;
  349. Procedure XAdjustSplitscreen( Line : Word ); external;
  350. Procedure XSetDoubleBuffer( PageHeight : Word ); external;
  351. Procedure XSetTripleBuffer( PageHeight : word ); external;
  352. Procedure XPageFlip( X, Y : Word ); external;
  353. Procedure XSetClipRect( Left, Top, Right, Bottom : Word ); external;
  354. Procedure XTextMode; external;
  355. Procedure XWaitVsync; external;
  356. Procedure XLine( x1, y1, x2, y2, Color, PgOffs : word ); external;
  357. Procedure XPutPix( X,Y,PgOfs,Color:word ); external;
  358. Function  XGetPix( x,y,PageBase:word ) : word; external;
  359. Procedure XRectFill( StartX,StartY,EndX,EndY,PageBase,Color:word ); external;
  360. Procedure XRectPattern( StartX,StartY,EndX,EndY,PageBase:word; var Pattern); external;
  361. Procedure XCpVidPage( SourceOffs, DestOffs : word ); external;
  362. Procedure XCpVidRect( SrcStartX,SrcStartY,SrcEndX,SrcEndY,DestStartX,
  363.                                             DestStartY,SrcPageBase,DestPageBase,SrcBitmapW,
  364.                                             DestBitmapW:word ); external;
  365. Procedure XShiftRect( SrcLeft,SrcTop,SrcRight,SrcBottom,DestLeft,DestTop,
  366.                                             ScreenOffs:word ); external;
  367. Procedure XCircle( Left, Top, Diameter, Color, ScreenOffs:word ); external;
  368. Procedure XFilledCircle( Left, Top, Diameter, Color, ScreenOffs:word ); external;
  369. Procedure XGetPalStruc( var PalBuff; NumColors,StartColor:word ); external;
  370. Procedure XGetPalRaw( Var PalBuff; NumColors,StartColor:word ); external;
  371. Procedure XPutPalStruc( Var CompPalBuff ); external;
  372. Procedure XTransposePalStruc( Var CompPalBuff; StartColor:word ); external;
  373. Procedure XPutPalRaw( Var PalBuff; NumColors,StartColor:word ); external;
  374. Procedure XSetRGB( ColorIndex,R,G,B:byte ); external;
  375. Procedure XRotPalStruc( Var PalBuff; Direction:word ); external;
  376. Procedure XRotPalRaw( Var PalBuff; Direction, NumColors:word ); external;
  377. Function  XCpContrastPalStruc( Var PalSrcBuff,PalDestBuff; Intensity:byte ) : word; external;
  378. Procedure XPutContrastPalStruc( Var CompPalBuff; Intensity:byte ); external;
  379. Function  XCharPut( Chr:char; X, Y, ScrnOffs, Color:word ) : byte; external;
  380. Procedure XSetFont( FontID : word ); external;
  381. Procedure XTextInit; external;
  382. Procedure XRegisterUserFont( var FontToRegister ); external;
  383. Function  XGetCharWidth( ch : char ) : byte; external;
  384. Procedure XTriangle( X0, Y0, X1, Y1, X2, Y2, Color, PageOffset:word ); external;
  385. Procedure XPolygon( var vertices; numvertices, Color, PageOffset:word ); external;
  386. Procedure XPutCursor( X, Y, TopClip, BottomClip, ScrnOffs : word ); external;
  387. Procedure XDefineMouseCursor( var MouseDef; MouseColor:byte ); external;
  388. procedure XMouseInit; external;
  389. Procedure XMouseWindow( x0, y0, x1, y1:word ); external;
  390. procedure XShowMouse; external;
  391. Procedure XHideMouse; external;
  392. Procedure XMouseRemove; external;
  393. Procedure XPositionMouse( X, Y : word ); external;
  394. Procedure XUpdateMouse; external;
  395. Function  XFloodFill( X, Y, PgOfs, Color:word ) : word; external;
  396. Function  XBoundaryFill( X, Y, PgOfs, BoundaryColor, Color : word ) : word; external;
  397. Procedure XInstallVSyncHandler( VrtsToSkip:word ); external;
  398. Procedure XRemoveVSyncHandler; external;
  399. Procedure XSetUserVSyncHandler; external;
  400.  
  401. function XPrintf( x, y, ScrnOffs, Color : word; s : string ) : integer;
  402. var
  403.     w, i : integer;
  404. begin
  405.     w := x;
  406.     for i := 1 to length(s) do
  407.         x:=x+XCharPut( s[i], x, y, ScrnOffs, color );
  408.     XPrintf := x-w+1;
  409. end;
  410.  
  411. function XStrWidth( s : string ) : integer;
  412. var
  413.     w, i : integer;
  414. begin
  415.     w := 0;
  416.     for i := 1 to length(s) do
  417.         w:=w+XGetCharWidth( s[i] );
  418.     XStrWidth := w;
  419. end;
  420.  
  421. function XBgPrintf( x, y, ScrnOffs, fgcolor, bgcolor : word; s : string ) : integer;
  422. var
  423.     i : integer;
  424. begin
  425.     for i := 1 to length(s) do
  426.     begin
  427.         XRectFill( x, y, x+XGetCharWidth(s[i]),y+CharHeight,ScrnOffs,bgcolor);
  428.         x := x + XCharPut( s[i], x, y, ScrnOffs, fgcolor);
  429.     end;
  430.     XBgPrintf := x;
  431. end;
  432.  
  433. Function XCentre( x, y, ScrnOffs, color : word; s : string ) : integer;
  434. var
  435.     w, i : integer;
  436. begin
  437.     w := 0;
  438.     for i := 1 to length(s) do
  439.         w:=w+XGetCharWidth( s[i] );
  440.     x := x-w div 2;
  441.     xprintf( x, y, ScrnOffs, color, s );
  442.     xcentre := x;
  443. end;
  444.  
  445. Function XBgCentre( x, y, ScrnOffs, fgcolor, bgcolor : word; s : string ) : integer;
  446. var
  447.     w, i : integer;
  448. begin
  449.     w := 0;
  450.     for i := 1 to length(s) do
  451.         w:=w+XGetCharWidth( s[i] );
  452.     x := x-w div 2;
  453.     xbgprintf( x, y, ScrnOffs, fgcolor, bgcolor, s );
  454.     xbgcentre := x;
  455. end;
  456.  
  457. End.
  458.  
  459.